//
//  CBJSearchView.swift
//  Weibo
//
//  Created by 崔健 on 16/5/19.
//  Copyright © 2016年 cbj. All rights reserved.
//

import UIKit

class CBJSearchView: UIView {


    @IBOutlet weak var searchTextFiled: UITextField!
    
    @IBOutlet weak var searchRightCons: NSLayoutConstraint!
    
    @IBAction func textEditBegin(sender: AnyObject) {
        

        // 改变右约束
        searchRightCons.constant = 50
        UIView.animateWithDuration(0.25) { 
            
            self.layoutIfNeeded()
        }
        
    }

    @IBAction func cancelBtnClick(sender: AnyObject) {
        
        // 清空textfiled
        searchTextFiled.text = ""
        
        searchRightCons.constant = 0
        UIView.animateWithDuration(0.25) {
            
            self.layoutIfNeeded()
        }
        
        self.endEditing(true)
    
    }
    
    override func awakeFromNib() {
        
        self.frame.size.width = kScreenWidth
        self.frame.size.height = 40
        self.backgroundColor = UIColor.clearColor()
//        searchTextFiled.layer.cornerRadius = 20;
//        searchTextFiled.layer.masksToBounds = true
        
        let leftView = UIImageView.init(image: UIImage(named: "searchbar_textfield_search_icon"))
        leftView.contentMode = .Center
        leftView.frame = CGRectMake(0, 0, 40, 40)
        searchTextFiled.leftView = leftView
        searchTextFiled.leftViewMode = .Always
        searchTextFiled.layer.borderWidth = 2
        searchTextFiled.layer.borderColor = UIColor.orangeColor().CGColor
        searchTextFiled.backgroundColor = UIColor.whiteColor()
    }
    
    
    
    class func loadSearchView() -> CBJSearchView{
    
        return NSBundle.mainBundle().loadNibNamed("SearchView", owner: nil, options: nil).last as! CBJSearchView
    }
    
}
